package com.erp.stock.controller;

import com.erp.common.ResponseMessage;
import com.erp.stock.entity.ProcessedProductionStock;
import com.erp.stock.service.ProcessedProductionStockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("processedProdStock")
public class ProcessedProductionStockController {

    @Autowired
    ProcessedProductionStockService service;

    @PostMapping("/add/list")
    public ResponseMessage addList(Long orderId){
        if (service.insertStocksByOrder(orderId)) {
            return ResponseMessage.ok();
        }
        return ResponseMessage.fail("添加加工品失败");
    }

    @GetMapping("/list")
    public ResponseMessage list(Long orderId) {
        List<ProcessedProductionStock> list = service.list(orderId);
        if (list.size() == 0) {
            return ResponseMessage.fail("无相关数据");
        }
        return new ResponseMessage(list);
    }
}
